package com.love.marriage.userCommissionWithdrawalHistory.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.love.marriage.userCommissionWithdrawalHistory.entity.UserCommissionWithdrawalHistory;
import com.love.marriage.userCommissionWithdrawalHistory.mapper.UserCommissionWithdrawalHistoryMapper;
import com.love.marriage.userCommissionWithdrawalHistory.service.UserCommissionWithdrawalHistoryService;
import com.love.marriage.userCommissionWithdrawalHistory.vo.UserCommissionWithdrawalHistoryVo;
import com.love.marriage.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * description:  用户提现回佣金额历史表服务实现类
 * author:       mybatisPlus
 * createDate:   2024-11-10 18:46:48
 * version:      1.0.0
 */
@Service
@RequiredArgsConstructor
public class UserCommissionWithdrawalHistoryServiceImp extends ServiceImpl<UserCommissionWithdrawalHistoryMapper, UserCommissionWithdrawalHistory> implements UserCommissionWithdrawalHistoryService {

    private final UserCommissionWithdrawalHistoryMapper userCommissionWithdrawalHistoryMapper;

    @Override
    public Page<UserCommissionWithdrawalHistoryVo> getPage(Long pageNum, Long pageSize, UserCommissionWithdrawalHistoryVo userCommissionWithdrawalHistoryVo) {
        Page<UserCommissionWithdrawalHistoryVo> page = new Page<>(pageNum == null ? 1 : pageNum, pageSize == null ? 10 : pageSize);
        return userCommissionWithdrawalHistoryMapper.getPage(page, userCommissionWithdrawalHistoryVo);
    }

    @Override
    public List<UserCommissionWithdrawalHistoryVo> getList(UserCommissionWithdrawalHistoryVo userCommissionWithdrawalHistoryVo) {
        return userCommissionWithdrawalHistoryMapper.getList(userCommissionWithdrawalHistoryVo);
    }

    @Override
    public UserCommissionWithdrawalHistoryVo queryUserCommissionWithdrawalHistory(Long id) {
        return userCommissionWithdrawalHistoryMapper.queryUserCommissionWithdrawalHistory(id);
    }

    @Override
    public UserCommissionWithdrawalHistoryVo addUserCommissionWithdrawalHistory(UserCommissionWithdrawalHistoryVo userCommissionWithdrawalHistoryVo) {
        UserCommissionWithdrawalHistory userCommissionWithdrawalHistory = new UserCommissionWithdrawalHistory();
        BeanUtils.copyProperties(userCommissionWithdrawalHistoryVo, userCommissionWithdrawalHistory);
        userCommissionWithdrawalHistoryMapper.insert(userCommissionWithdrawalHistory);
        UserCommissionWithdrawalHistoryVo res = new UserCommissionWithdrawalHistoryVo();
        BeanUtils.copyProperties(userCommissionWithdrawalHistory, res);
        return res;
    }

    @Override
    public UserCommissionWithdrawalHistoryVo updateUserCommissionWithdrawalHistory(UserCommissionWithdrawalHistoryVo userCommissionWithdrawalHistoryVo) {
        UserCommissionWithdrawalHistory userCommissionWithdrawalHistory = new UserCommissionWithdrawalHistory();
        BeanUtils.copyProperties(userCommissionWithdrawalHistoryVo, userCommissionWithdrawalHistory);
        userCommissionWithdrawalHistoryMapper.updateById(userCommissionWithdrawalHistory);
        return userCommissionWithdrawalHistoryVo;
    }

    @Override
    public Boolean deleteUserCommissionWithdrawalHistory(String ids) {
        if(StringUtils.isEmpty(ids)) {
            return true;
        }
        List<String> idArr = Arrays.asList(ids.split(","));
        userCommissionWithdrawalHistoryMapper.deleteBatchIds(idArr);
        return true;
    }
}
